from app.forms.article import audio_status


def register_filter(app):
    @app.template_filter('strftime')
    def datetime_strftime(time):
        if time is None:
            return '不能为空'
        return time

    @app.template_filter('audit_status')
    def audit_status(status):
        if status in audio_status:
            return audio_status[status]
        return 'None'

    @app.template_filter('audit_status_button')
    def audit_status_button(status):
        if status == 9:
            return 'secondary'
        elif status == 8:
            return 'danger'
        elif status == 7:
            return 'success'
        else:
            return 'secondary'

    @app.template_filter('user_status')
    def user_status(status):
        return '已审核' if status == 100 else '未审核'

    @app.template_filter('user_status_button')
    def user_status_button(status):
        if status == 100:
            return 'success'
        elif status == 101:
            return 'danger'
        else:
            return 'secondary'
